package com.artisan.boottraditionaldesign.factory;

import com.artisan.boottraditionaldesign.service.MessageService;
import com.artisan.boottraditionaldesign.service.impl.EmailService;
import com.artisan.boottraditionaldesign.service.impl.SMSService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageServiceFactory {

    private final EmailService emailService;
    private final SMSService smsService;

    @Autowired
    public MessageServiceFactory(EmailService emailService, SMSService smsService) {
        this.emailService = emailService;
        this.smsService = smsService;
    }

    /**
     * 仅为demo , 可以考虑自定义注解
     * @param type
     * @return
     */
    public MessageService createService(String type) {
        if ("email".equals(type)) {
            return emailService;
        } else if ("sms".equals(type)) {
            return smsService;
        } else {
            throw new IllegalArgumentException("Unknown service type");
        }
    }
}
